<?php
namespace app\admin\controller;
use app\admin\controller\Common;
use app\service\adminService;
use think\Db;
use auth\Auth;
use think\Session;
use app\service\wotuService;
class Uface extends Common
{
    public function test(){
        $personGuid="8A187EC8EC3348AB8DD0ABF6E8C1A944";
        $deviceKey="84E0F4213A2901FA";
        $taskid="E72B843B609D45E290EC60B831E032BB";
        $type=1;
        $res=(new wotuService())->photodevreg($personGuid,$deviceKey);
        var_dump($res);
    }
    public function test2(){
        $personGuid="8A187EC8EC3348AB8DD0ABF6E8C1A944";
        $deviceKey="84E0F4213A2901FA";
        $taskId="14D7005B004A4167881C2ABA4B3986B0";
        $type=1;
        $res=(new wotuService())->devregquery($personGuid,$deviceKey,$taskId);
        var_dump($res);
    }
    public function test3(){
        $personGuid="8A187EC8EC3348AB8DD0ABF6E8C1A944";
        $deviceKey="84E0F4213A2901FA";
        $taskId="37E25FA884BB42DABAF4027DC7B17FAC";
        $type=1;
        $state=5;
        $res=(new wotuService())->devregupdate($personGuid,$state,$deviceKey,$taskId);
        var_dump($res);
    }
    public function ufacelist(){
        $userlist=(new wotuService())->people();
        $data=json_decode($userlist,true);
        if($data["code"]=="GS_SUS208"){

        }else{
            return $data["msg"];
        }
        echo "<pre>";
        var_dump($data["data"]);
    }

	public function userList(){
        //查询小区管理员数据
        $list = Db::table("uface_admin")->order("id desc")->select();
        
        $this->assign('list',$list);
        //查询管理员数据条数
        $number =  Db::table("uface_admin")->count();
        $this->assign('number',$number);
        return $this->fetch('user_list');
    }
    public function userAdd(){
        if(request()->isPost()){
            //获取表单数据
            $data = request()->post();
            
            //判断账号名称是否重复
            $info = Db::table("uface_admin")->where("phone",$data["phone"])->where("name",$data["name"])->find();
            if($info){
                $this->error('账号或姓名已存在');
            }
            $communityinfo=Db::table("community")->where("id",$data["community_id"])->find();
            //将数据插入数据库
            $result =Db::table("uface_admin")->insert($data);
            //判断数据是否插入成功
            if($result){
                
                $this->success('添加管理员成功',url('adminList'));
            }else{
                $this->error('添加管理员失败',url('adminAdd'));
            }
        }else{
        	$communitylist=Db::table("community")->select();
        	$this->assign("communitylist",$communitylist);
            return $this->fetch('user_add');
        }
    }
    public function userDel(){
		$request = request();
		$id = $request->param('id');
		$validate = $this->validate($request->param(),[
			'id'	=>	'require|number'
		]);
		if($validate !== true){
			$this->error($validate);
        }
        //判断是否存在该数据
        $info = Db::table("uface_admin")->where("id",$id)->find();
        if(empty($info)){
            $this->error('该管理员不存在');
		}
        $result = Db::name('uface_admin')->delete($id);
        if($result){
           
            $this->success('删除管理员成功',url('userList'));
		}else{
            $this->success('删除管理员失败',url('userList'));
		}
    }
}